import request from '@/utils/request'

// 获取分类列表
export function getCategoryList(params) {
  return request({
    url: '/categories',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 获取分类数量
export function getCategoryAmount(params) {
  return request({
    url: '/categories/count',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 新增分类
export function addCategory(data) {
  return request({
    url: '/categories',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 删除分类
export function deleteCategory(id) {
  return request({
    url: `/categories/${id}`,
    method: 'delete',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 编辑分类
export function editCategory(data) {
  return request({
    url: `/categories/${data.id}`,
    method: 'put',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

// 获取指定的分类
export function getOneCategory(params) {
  return request({
    url: `/categories/${params.id}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
